class Solution {
public:
    int LastRemaining_Solution(unsigned int n, unsigned int m)
    {
        if(n<1 || m<1)
			return -1;
		if(n==1)
			return 0;
		return (LastRemaining_Solution(n-1,m)+m)%n;
    }
};